<script>
function dualwindow(a,b){
    width=screen.width/2-5;
    setting='width='+width+',height='+screen.height+',scrollbars=yes,toolbar=no,left=0';
    asetting='width='+width+',height='+screen.height+',scrollbars=yes,toolbar=no,left='+screen.width/2;
    window.open(a,'Previos',setting);
    window.open(b,'Report',asetting);
    setTimeout(function(){
        window.open('', '_self', '');
        window.close();
    }, 100);
}

</script>
<?php
echo $html->css('baseminutes','stylesheet',array(),false);
echo $html->css($minuteType['code'],'stylesheet',array(),false);
?>
<div id="minutes_container">
<div class="minutes_status">
<?php
if ($minutes_approved ) {
    echo __('Minutes status').": <span class='minutes_status_approved'>".__('Approved',true)."</span>";
} else {
    echo __('Minutes status').": <span class='minutes_status_pending'>".__('Pending approval',true)."</span>";
    if (!empty($chairperson) || !empty($permission['Minute approval']['Create'])) {
        echo "<div class='approve_minutes'>";
        echo '[ '.$html->link(__('Approve this minutes',true),array('committee'=>$this->params['committee'],'controller'=>'meetings','action'=>'approve_minutes','id'=>$this->params['id'])).' ]';
        if(!empty($prev) && !$minutes_approved){
            echo ' [ ';
            echo  $html->link(__('View Previous Meeting Report',true), '#',array('onclick'=>"dualwindow('../../../".$this->params['committee']."/reports/meeting/".$prev['Meeting']['id']."','../../../".$this->params['committee']."/decisions/printminutes/".$this->params['id']."');")); 
            echo ' ]';
        }
        echo "</div>";
    }
    
}
?>
</div>
<?php
// ------------------- HEADER ------------------------//
$name = (!empty($chairperson_detail)) ? $chairperson_detail['Title']['short_name'].' '.$chairperson_detail['User']['name'] : __('No chairperson selected',true);
$summary = 
    '<div class="minutes_summary">
        <h2 class="title">'.__('Minutes',true).'<br/>'.$meeting['Meeting']['meeting_title'].'<br/>'.$meeting['Meeting']['meeting_num'].'</h2>
    
        <table cellpadding="2" align="center" class="header">
            <tr id="summary_date">            
                <td align="left" valign="top" width="30%">'.__('Date',true).'</td>
                <td align="left" valign="top" width="3%">:</td>
                <td align="left" valign="top">'.$html->converttolongdate(date("d/m/Y",strtotime($meeting["Meeting"]["meeting_date"]))).'</td>
            </tr>
            <tr id="summary_time">            
                <td align="left" valign="top">'.__('Time',true).'</td>
                <td align="left" valign="top">:</td>
                <td align="left" valign="top">'.$html->converttimeam(date("H:i a",strtotime($meeting["Meeting"]["meeting_date"]))).'</td>
            </tr>
            <tr id="summary_venue">            
                <td align="left" valign="top">'.__('Venue',true).'</td>
                <td align="left" valign="top">:</td>
                <td align="left" valign="top">'.$meeting["Meeting"]["venue"].'</td>
            </tr>
            <tr id="summary_chairperson">            
                <td align="left" valign="top">'.__('Chairperson',true).'</td>
                <td align="left" valign="top">:</td>
                <td align="left">
    ';
    
    $summary.= $name;
    $summary.= '</td>
            </tr>
            <tr id="summary_attendance">            
                <td align="left" valign="top">'.__('List of attendance',true).'</td>         
                <td align="left" valign="top">:</td>
                <td align="left" valign="top">'.__('Appendix A', true).'</td>
            </tr>
        </table>
    </div>
    ';
    
// ------------------- THE MINUTES ------------------------//
$minutes = '<div id="minutestable">'.$this->element("minutes/displayminutes",array("decisions"=>$decisions,"meetingid"=>$meetingid)).'</div>';

// ------------------- ATTENDANCE LIST ------------------------//
if(empty($invitees)){
    $attendance = '';
}else{
$attendance = '<div id="att">';
$attendance.= '<h2 class="att_title">'.__('Appendix A',true).'</h2>';
if ($invitees) {
    $attendance.= '<h3 class="att_title">'.__("Present",true).':</h3>';
    $attendance.= "<table cellpadding='2' cellspacing='2' class='att_list'>";
    $i = 1;
    foreach ( $invitees as $invitee ) {
        $attendance .= "<tr><td class='number'>".$i++.".</td><td class='name'>".$invitee['Title']['short_name'].' '.$invitee['User']['name'];
        if ($invitee['Attendance']['attend_as'] == '2') // chairperson
            $attendance .= ' - '.__('CHAIRPERSON',true);
        if ($invitee['Attendance']['attend_as'] == '1') // secretariat
            $attendance .= ' - '.__('SECRETARIAT',true);
        $attendance .= "</td></tr>";
        $attendance .= "<tr><td>&nbsp;</td><td class='post'>".$invitee['User']['job_title'];
        if (!empty($invitee['User']['bahagian'])) $attendance .= ', '.$invitee['User']['bahagian'];
        $attendance .= "</td></tr>";
    }
    $attendance .= "</table>";
}

if ($didntcome) {
    $attendance.= '<div id="att"><h3 class="att_title">'.__("Absent with apologies",true).':</h3>';
    $attendance.= "<table cellpadding='2' cellspacing='2' class='att_list'>";
    $i = 1;
    foreach ( $didntcome as $invitee ) {
        $attendance .= "<tr><td class='number'>".$i++.".</td><td class='name'>".$invitee['Title']['short_name'].' '.$invitee['User']['name'];
        $attendance .= "</td></tr>";
        $attendance .= "<tr><td>&nbsp;</td><td class='post'>".$invitee['User']['job_title'];
        if (!empty($invitee['User']['bahagian'])) $attendance .= ', '.$invitee['User']['bahagian'];
        $attendance .= "</td></tr>";
    }
    $attendance .= "</table>";

}
$attendance.= '</div>';
}

// ------------------- SIGNATURE -------------------//
$signature = '<div id="signature">
    <p class="signature">'
        .__('Prepared by',true).',
        <br>
        <br>
        <br>
        ---------------------------------
        <br>
        ('.$secretariat['Title']['short_name'].' '.$secretariat['User']['name'].')
    </p>
    <br>
    <p class="signature">'
        .__('Approved by',true).',
        <br>
        <br>
        <br>
        ---------------------------------
        <br>
        ('.$chairperson_detail['Title']['short_name'].' '.$chairperson_detail['User']['name'].')
    </p>
    </div>';

$phrase  = '<div id="minutes_wrap">'.$minuteType['format'].'</div>';
$source = array("[%summary]", "[%attendance]", "[%minutes]", "[%signature]");
$list   = array($summary, $attendance, $minutes, $signature);
$newphrase = str_replace($source, $list, $phrase);

echo $newphrase;
?>
</td>
</div>

